/*
 * @Description: 消防员
 * @Date: 2022-04-12 14:44:58
 * @Author: yeming
 */

import Overlay from 'ol/Overlay'
import { elementStr2Node } from '../common/svg.js'
import { fromLonLat, toLonLat } from 'ol/proj.js'
import { Point, Point3d } from '../model/point.js'
import { Line, Line3d } from '../model/line/line.js'
import { Circle, Circle3d } from '../model/circle.js'


const PLANE_COLOR_LIST = ['blue', 'green', 'red', 'yellow', 'purple']

class AirGroundCoo {
  constructor(ol2d, ol3d, uavHashMap, popupHashMap, vectorSource) {
    this.ol2d = ol2d
    this.ol3d = ol3d
    this.map2d = ol2d.map2d
    this.uavHashMap = uavHashMap
    this.popupHashMap = popupHashMap
    this.vectorSource = vectorSource // 矢量标注的数据源 addFeature(), getFeatures(), removeFeature()
    this.feature = null
  }

  addAirGroundCooUav (sessionId, type, latlng, style, rend3d = true) {
    if (this.colorIndex > PLANE_COLOR_LIST.length - 1) this.colorIndex = 0
    let planeImg = this.setUav2dImg(sessionId, this.colorIndex, style)

    const uav2d = new Overlay({
      sessionId: sessionId,
      id: sessionId, // 当前选中的飞机sn
      type: type,
      rend3d: rend3d, // 是否渲染3d 默认值为false
      element: elementStr2Node(planeImg), // 飞机dom元素
      offset: [-23, -23] // 图标中心点位置
    })
    // 2d无人机姿态及位置
    uav2d.setPosition(fromLonLat(latlng))
    this.map2d.addOverlay(uav2d)

    this.colorIndex++
  }

  addFiremen (id, cssText, latlng) {


  }

  addPopupOverlay (id, latlng, popupData, cssText, offset) {

  }

  /**
   * @desc: 设置2d飞机图标（数组循环设置）
   * @param {Number} index 索引
   * @return {*}
   * @use: 使用示例
   */
  setUav2dImg (id, index, style) {
    let fillColor = ''
    if (!style || !style.fillColor) fillColor = PLANE_COLOR_LIST[index]
    else fillColor = style.fillColor

    let planeSvg = '<div class="air-ground-uav-main" id="' + id + '"><svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="46px" height="46px" viewBox="0 0 46 46" style="cursor: pointer;">' +
      // '<g id="svgOutPath_' + id + '" class="svg-uav-breath">' +
      // '<path d="M7,39 L7,45 L1,39 L7,39 Z M45,39 L39,45 L39,39 L45,39 Z M7,1 L7,7 L1,7 L7,1 Z M39,1 L45,7 L39,7 L39,1 Z" fill="#FFFFFF"></path>' +
      // '<ellipse cx="23" cy="23" rx="18" ry="18" fill="#FFFFFF00" stroke="#FFFFFF" stroke-width="2"></ellipse>' +
      // '</g>' +
      // '<g>' +
      '<path id="svgUavPath_' + id + '" d="M23,28 L11,33 L23,8.5 L35,33 L23,28 Z" fill="' + fillColor + '" stroke="#FFFFFF" stroke-width="2"></path>' +
      '</g>' +
      '</svg></div>'
    return planeSvg
  }
}

export default AirGroundCoo
